package com.my.Config;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.orm.jpa.EntityManagerFactoryUtils;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;
import java.util.Properties;

@Configuration
@ComponentScan("com.my")
public class RootConfig {
  //事务配置
  @Bean
  public PlatformTransactionManager platformTransactionManager(DataSource dataSource){

    return new DataSourceTransactionManager(dataSource);
  }

  @Bean
  public JdbcTemplate jdbcTemplate(DataSource dataSource){
    JdbcTemplate jdbcTemplate=new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);
    return jdbcTemplate;
  }
  //配置数据源
  @Bean
  public DataSource dataSource() throws Exception {

    ComboPooledDataSource dataSource=new ComboPooledDataSource();
    dataSource.setJdbcUrl("jdbc:mysql:///javatest?useUnicode=true&characterEncoding=utf-8&useSSL=true");
     dataSource.setPassword("123456");
    dataSource.setDriverClass("com.mysql.jdbc.Driver");
    dataSource.setUser("root");

    return dataSource;
  }



  }



